<!DOCTYPE html>
<html>
	<!--
		作者：offline
		时间：2018-06-27
		描述：试用期管理
	-->

	<head>
		<!-- 引入框架文件 -->
		<link rel="stylesheet" href="../../model/bootstrap-3.3.7-dist/css/bootstrap.min.css" />
		<script type="text/javascript" src="../../model/jquery-2.1.0.js"></script>
		<script type="text/javascript" src="../../model/bootstrap-3.3.7-dist/js/bootstrap.js"></script>
		<link rel="stylesheet" href="../../static/css/ehr.css" />
		<link rel="stylesheet" href="../../static/css/employee.css" />
		<script type="text/javascript" src="../../model/models.js"></script>
		<script type="text/javascript" src="../../model/dispose.js"></script>
		<style type="text/css">
			.show td {
				text-align: center;
			}
			
			.show th {
				text-align: center;
			}
		</style>
		<meta charset="UTF-8">
		<title></title>
	</head>

	<body>
		<div include="../../static/header.htm"></div>
		<div style="height: 100%;float: left;" include="../../static/aside.htm"></div>

		<div class="aside2">
			<div include="../../static/empManage.htm"></div>
		</div>

		<div class="section">
			<div style="color: white;font-size: 36px;text-align: center; width: 100%; height: 70px;" class="head"><b>试用期管理</b></div>
			<div class="content">
				<!-- 试用期管理 -->
				<div class="amend">
					<form id="findProbation">
						<div>
							<input id="key" value="" type="text" placeholder="试用期员工姓名/编号" class="form-control" style="width: 200px; float: left;"/>
							<input style="margin: 2px 5px; width: 100px;" type="submit" value="查询" class="btn btn-danger" />
						</div>
					</form>
					<form id="updatePro">
						<div>
							<div class="input-group">
								<span style="float: none;" class="input-group-addon" id="basic-addon1">员工姓名：</span>
								<input id="empName" readonly="readonly" style="width: 200px;" type="text" class="form-control" aria-describedby="basic-addon1">
								<input type="hidden" id="proId" />
							</div>
							<div class="input-group">
								<span style="float: none;" class="input-group-addon" id="basic-addon1">员工编号：</span>
								<select onchange="showMsg(this)" id="id" name="id" class="form-control" style="width: 200px;">
									<option>员工编号</option>
								</select>
							</div>
						</div>

						<div>
							<select id="status" class="form-control" style="width: 200px;">
								<option value="转正">试用期转正</option>
								<option value="延期">试用期延期</option>
								<option value="不通过">试用期不通过</option>
							</select>
						</div>

						<div>
							<input style="width: 295px; margin-top: 20px;" type="submit" class="btn btn-danger"/>
						</div>
					</form>
				</div>
				<!-- 信息查询 -->
				<div class="query">
					<div>
						<form id="findByDate">
							<!-- 已转正员工信息查询 -->
							<h3>已转正员工信息查询</h3>
							<!-- 搜索输入框 -->
							<span style="margin-top: 7px;">开始时间：</span>
							<input id="beginDate" name="beginDate" value="2016-06-07" type="date" class="form-control" style="width: 150px;margin-right: 10px;" />
							<span style="margin-top: 7px;">结束时间：</span>
							<input id="endDate" name="endDate" value="2018-09-03" type="date" class="form-control" style="width: 150px;margin-right: 10px;" />
							<input class="btn btn-primary" type="submit" value="查询" style="width: 100px;margin-top: 5px; margin-left: 100px;" />
							<input type="hidden" value="1" id="page" name="page" />
						</form>

						<!-- <form id="searchUser3">
							试用期员工信息查询 -->
							<!-- 搜索输入框 
							<input id="beginDate" name="beginDate" type="text" class="form-control" placeholder="" />
							<input class="btn btn-primary" type="submit" value="查询" style="width: 100px;margin-top: 5px; margin-left: 100px;" />
							<input type="hidden" value="1" id="page" name="page" />

						</form>-->

					</div>
				</div>

				<div class="show">
					<table class="table table-striped">
						<thead>
							<tr>
								<th>员工编号</th>
								<th>姓名</th>
								<th>性别</th>
								<th>部门名称</th>
								<th>岗位名称</th>
								<th>联系电话</th>
								<th>电子邮件</th>
								<th>所学专业</th>
								<th>试用期开始时间</th>
								<th>试用期结束时间</th>
								<th>试用状态</th>
							</tr>
						</thead>

						<tbody id="searchUserList">
							<tr>
								<td></td>
								<td></td>
								<td></td>
								<td></td>
								<td></td>
								<td></td>
								<td></td>
								<td></td>
								<td></td>
							</tr>
						</tbody>

					</table>

					<!-- 分页开始 -->
					<nav id="page" style="position: absolute; bottom: 20px;" aria-label="Page navigation">
						<ul id="pagination" class="pagination">
							<li>
								<a href="#" aria-label="Previous">
									<span aria-hidden="true">&laquo;</span>
								</a>
							</li>
							<li>
								<a href="#" aria-label="Next">
									<span aria-hidden="true">&raquo;</span>
								</a>
							</li>
						</ul>
					</nav>

					<!-- 分页结束 -->

				</div>
			</div>
		</div>
	</body>

</html>

<script type="text/javascript">
	// 根据key查询封装
	var page = 1;
	/**
	 * 
	 * @param {Object} key   关键字
	 * @param {Object} flag	 控制select的刷新
	 * @param {Object} status	形式
	 * @param {Object} page		当前页
	 */
	function findByKey(key, flag, status, page) {

		$.ajax({
			type: "post",
			url: "http://localhost:9090/findProbationByKey?key=" + key + "&status=" + status + "&page=" + page,
			"success": function(obj) {
				//debugger;断点
				if(null != obj.data) {
					//alert(obj.msg);
					// 显示分页数据
					page = obj.page;
					upPage("pagination", obj.page);

					var list = obj.data;

					var $tbody = $("#searchUserList");
					$tbody.html("");
					// 如果只有一条数据的话就更新proId的值
					if(1 == list.length) {
						$("#proId").val(list[0].id);
					} else {
						$("#proId").val(-1);
					}
					if(flag) {
						$("#id").html("");
					}

					for(var i = 0; i < list.length; i++) {
						var $tr = $("<tr></tr>");

						var user = list[i];
						// 员工信息显示
						for(var index in user) {
							if("proEmp" == index) {
								var h = 0;
								var emp = user[index];
								for(var j in emp) {
									if(h > 7)
										break;
									if("empDiv" == j && emp[j] != null) {
										var $td = $("<td>" + emp[j].depaName + "</td>");
									} else if("empPost" == j && emp[j] != null) {
										var $td = $("<td>" + emp[j].postName + "</td>");
									} else {
										var $td = $("<td>" + emp[j] + "</td>");
									}

									$("#" + j).val(emp[j]);

									$tr.append($td);

									h++;
								}
							}
						}
						var j = 0;
						for(var index in user) {

							if(j > 3) break;
							if("proEmp" != index && "id" != index) {
								var $td = $("<td>" + user[index] + "</td>")
								$tr.append($td);
							}
							j++;
						}
						if(flag)
							$("#id").append("<option value='" + user.proEmp.id + "'>" + user.proEmp.id + "</option>");
						$tbody.append($tr);
					}
				}
			},
			"dataType": "json",
			async: true
		});
	}

	//挂载事件，当表单提交时进行处理
	$("#findProbation").submit(function(e) {

		var key = $("#key").val();
		//阻止表单默认事件，不让表单跳转到其他页面
		e.preventDefault();

		//jq的回调函数中的this，一般表示该事件源，即触发事件的元素
		var $self = $(this);
		//$self.serialize();将表单中的数据进行序列化
		//async:true 采用异步操作
		$("#id").html("");
		findByKey(key, true, "正常", 1);

	})
	// 更新按钮提交
	$("#updatePro").submit(function(e) {

		e.preventDefault();
		// 获取proId的值
		var proId = $("#proId").val();
		// 获取status的值
		var status = $("#status").val();

		var $self = $(this);

		$.ajax({
			type: "post",
			url: "http://localhost:9090/updateProbationById?proId=" + proId + "&status=" + status,
			"success": function(obj) {
				if(obj.data) {
					window.wxc.xcConfirm("更新成功！", "success");
				} else {
					window.wxc.xcConfirm("更新失败！", "error");
				}
			},
			"dataType": "json",
			async: true
		});
	});

	// 员工id下拉框 
	function showMsg(obj) {
		var opt = obj.options[obj.selectedIndex];
		//		alert("The option you select is:" + opt.text + "(" + opt.value + ")");
		findByKey(opt.value, false, "正常", 1);
	}

	// 分页标签的单击事件
	function pageSkip(page) {
		var key = $("#key").val();

		findByKey(key, true, "正常", page);
	}

	$("#findByDate").submit(function(e) {
		e.preventDefault();

		var $self = $(this);

		$.ajax({
			type: "post",
			url: "http://localhost:9090/findByDate",
			"data": $self.serialize(),
			"success": function(obj) {
				//debugger;断点
				if(null != obj.data) {
					//alert(obj.msg);
					// 显示分页数据
					page = obj.page;
					upPage("pagination", obj.page);

					var list = obj.data;

					var $tbody = $("#searchUserList");
					$tbody.html("");
					// 如果只有一条数据的话就更新proId的值
					if(1 == list.length) {
						$("#proId").val(list[0].id);
					} else {
						$("#proId").val(-1);
					}
					$("#id").html("");

					for(var i = 0; i < list.length; i++) {
						var $tr = $("<tr></tr>");

						var user = list[i];
						// 员工信息显示

						if("转正" == user.status) {
							for(var index in user) {
								if("proEmp" == index) {
									var h = 0;
									var emp = user[index];
									for(var j in emp) {
										if(h > 7)
											break;
										if("empDiv" == j && emp[j] != null) {
											var $td = $("<td>" + emp[j].depaName + "</td>");
										} else if("empPost" == j && emp[j] != null) {
											var $td = $("<td>" + emp[j].postName + "</td>");
										} else {
											var $td = $("<td>" + emp[j] + "</td>");
										}

										$("#" + j).val(emp[j]);

										$tr.append($td);

										h++;
									}
								}
							}
							var j = 0;
							for(var index in user) {

								if(j > 3) break;
								if("proEmp" != index && "id" != index) {
									var $td = $("<td>" + user[index] + "</td>")
									$tr.append($td);
								}
								j++;
							}
							$("#id").append("<option value='" + user.proEmp.id + "'>" + user.proEmp.id + "</option>");
							$tbody.append($tr);
						}
					}
				}
				else {
					window.wxc.xcConfirm("查询无结果！", "error");
				}
			},
			"dataType": "json",
			async: true
		});
	});
</script>